package m.jclecai.com.view;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import m.jclecai.com.R;

import m.jclecai.com.adapter.PopWindowAdapter;

/**
 * Created by hp on 2017/3/22.
 */

public class MyPopWindow extends PopupWindow {

    private final BallGridView gridview;

    public MyPopWindow(Activity context){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View conentView = inflater.inflate(R.layout.fragment_hemai_popuwindow,null);
        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        gridview = (BallGridView) conentView.findViewById(R.id.gridview);
        String[] names = context.getResources().getStringArray(
                R.array.jczq_types_name_list);
        String[] types = context.getResources().getStringArray(R.array.jczq_types_list);
        PopWindowAdapter heMaiPopuWindowAdapter = new PopWindowAdapter(context,names,types);
        gridview.setAdapter(heMaiPopuWindowAdapter);
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(w);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(gridview.getMeasuredHeight() + 10);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setBackgroundDrawable((context.getResources().getDrawable(R.color.listview_item_shaung)));
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        this.setAnimationStyle(R.style.AnimationPreview);
    }

    public void showPopupWindow(View parent) {
        if (this.isShowing()) {
            this.dismiss();
        } else {
            this.showAsDropDown(parent);
        }
    }
}
